import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
var _excluded = ["executorId"];
import request from 'utils/request';
import { CPAAS_SDR } from 'utils/config';
import { getCurrentOrganizationId, isTenantRoleLevel, parseParameters } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
var organizationRoleLevel = isTenantRoleLevel();
/**
 * 查询列表数据
 * @async
 * @function fetchExecutable
 * @param {Object} params - 查询参数
 * @param {String} [params.page = 0] - 页码
 * @param {String} [params.size = 0] - 页数
 */

export function fetchExecutable(_x) {
  return _fetchExecutable.apply(this, arguments);
}
/**
 * 查询详情
 * @async
 * @function fetchExecutableDetail
 * @param {Object} params - 查询参数
 */

function _fetchExecutable() {
  _fetchExecutable = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            param = parseParameters(params);
            return _context.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/executables") : "".concat(CPAAS_SDR, "/v1/executables"), {
              method: 'GET',
              query: param
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchExecutable.apply(this, arguments);
}

export function fetchExecutableDetail(_x2) {
  return _fetchExecutableDetail.apply(this, arguments);
}
/**
 * 创建
 * @async
 * @function createExecutable
 * @param {String} params - 保存参数
 */

function _fetchExecutableDetail() {
  _fetchExecutableDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/executables/").concat(params.executableId) : "".concat(CPAAS_SDR, "/v1/executables/").concat(params.executableId), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _fetchExecutableDetail.apply(this, arguments);
}

export function createExecutable(_x3) {
  return _createExecutable.apply(this, arguments);
}
/**
 * 修改
 * @async
 * @function updateExecutable
 * @param {String} params.enabledFlag - 是否启用
 */

function _createExecutable() {
  _createExecutable = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/executables") : "".concat(CPAAS_SDR, "/v1/executables"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _createExecutable.apply(this, arguments);
}

export function updateExecutable(_x4) {
  return _updateExecutable.apply(this, arguments);
}
/**
 * 删除头
 * @async
 * @function deleteHeader
 * @param {object} params - 请求参数
 */

function _updateExecutable() {
  _updateExecutable = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/executables") : "".concat(CPAAS_SDR, "/v1/executables"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _updateExecutable.apply(this, arguments);
}

export function deleteHeader(_x5) {
  return _deleteHeader.apply(this, arguments);
}
/**
 * 执行器列表配置
 * @async
 * @function executorConfig
 * @param {object} params - 查询条件
 */

function _deleteHeader() {
  _deleteHeader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/executables") : "".concat(CPAAS_SDR, "/v1/executables"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _deleteHeader.apply(this, arguments);
}

export function executorConfig(_x6) {
  return _executorConfig.apply(this, arguments);
}
/**
 * 执行器列表配置
 * @async
 * @function executorConfig
 * @param {object} params - 查询条件
 */

function _executorConfig() {
  _executorConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/executor-configs/").concat(params.executorId, "/config") : "".concat(CPAAS_SDR, "/v1/executor-configs/").concat(params.executorId, "/config"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _executorConfig.apply(this, arguments);
}

export function executorConfigByExecutable(_x7) {
  return _executorConfigByExecutable.apply(this, arguments);
}

function _executorConfigByExecutable() {
  _executorConfigByExecutable = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    var executorId, others;
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            executorId = params.executorId, others = _objectWithoutProperties(params, _excluded);
            return _context7.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/executor-configs/").concat(executorId, "/by-executable") : "".concat(CPAAS_SDR, "/v1/executor-configs/").concat(executorId, "/by-executable"), {
              method: 'GET',
              query: others
            }));

          case 2:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _executorConfigByExecutable.apply(this, arguments);
}